<?php
class KonsumsiRapat extends Rapat {
	public $requestKonsumenStatus;
	public $requestKonsumenId;
	public $typeMakanan;
	public $bulan;
	public $tahun;

	public function  rules() {
		$rules = parent::rules();
		$rules[] = array(
			'bulan,tahun,typeMakanan,requestKonsumenStatus,requestKonsumenId, time_start', 'safe', 'on'=>'search',
		);
		
		return $rules;
	}
	
	

public function getTypeMakanan(){
		$makanan = $this->requestKonsumen->makananKonsumens;
		$result = "";
		if ($makanan!=null)
		foreach ($makanan as $m){
			
			$result .=  $m->type->name . " : ";
			
		}
		
		return $result;
	
	}
	
public static function getnamaHarifromDate($day,$month,$year){
	$date = date("N", mktime(0, 0, 0,(int)$day , (int)$month, (int)$year));
	switch ($date) {
	    case 1:
	        return "Senin";
	        break;
	    case 2:
	        return "Selasa";
	        break;
	    case 3:
	        return "Rabu";
	        break;
	    case 4:
	        return "Kamis";
	        break;
	    case 5:
	        return "Jumat";
	        break;	  	      	        
	    case 6:
	        return "Sabtu";
	        break;
	    case 7:
	        return "Minggu";
	        break;	        	        
}
	
	

}

	public function getJumlahMakanan(){
		$makanan = $this->requestKonsumen->makananKonsumens;
		$result = "";
		if ($makanan!=null)
		foreach ($makanan as $m){
			
			$result .= $m->quantity . " : ";
		
		}
		
		return $result;
	
	}
	
	public static function formatDate($date){
		
		$totaltime = strtotime($date);
		
		$date = date('d/m/Y',$totaltime);
		return $date;
	
	}
	
	
	public function getStatus(){
		$status = $this->requestKonsumen->status;
		
		return $status;
	}
	
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->with=array('requestKonsumen', 'requestKonsumen.makananKonsumens.type');
		$criteria->compare('t.id',$this->id);
		$criteria->compare('t.name',$this->name,true);
		$criteria->compare('t.room_id',$this->room_id);
		$criteria->compare('t.user_id',$this->user_id,true);
		$criteria->compare('t.date',$this->date,true);
		$criteria->compare('t.time_start',$this->time_start,true);
		$criteria->compare('t.time_end',$this->time_end,true);
		$criteria->compare('t.participant',$this->participant);
		$criteria->compare('t.message',$this->message,true);
		$criteria->compare('t.status',$this->status);
        $criteria->together=true;
        $criteria->compare('requestKonsumen.id', $this->requestKonsumenId,true);
        $criteria->compare('requestKonsumen.status',$this->requestKonsumenStatus,true);
        $criteria->compare('type.id',$this->typeMakanan);
        
        
     //   $sort = new CSort;
           //     $sort->defaultOrder = 'requestKonsumen.id ASC';
             //   $sort->attributes = array(
                			
               //     'Request Konsumen ID' => array(
                 //           'asc'=>'requestKonsumen.id',
                   //         'desc'=>'requestKonsumen.id DESC',
                     //   ),
               // );
                       
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria, //'sort' =>$sort
		));
	}
	
	public function searchByDate($date) {
		$criteria=new CDbCriteria;
		$criteria->with=array('requestKonsumen', 'requestKonsumen.makananKonsumens.type');
		$criteria->compare('t.id',$this->id);
		$criteria->compare('t.name',$this->name,true);
		$criteria->compare('t.room_id',$this->room_id);
		$criteria->compare('t.user_id',$this->user_id,true);
		$criteria->compare('t.date',$date);
		$criteria->compare('t.time_start',$this->time_start,true);
		$criteria->compare('t.time_end',$this->time_end,true);
		$criteria->compare('t.participant',$this->participant);
		$criteria->compare('t.message',$this->message,true);
		$criteria->compare('t.status',$this->status);
        $criteria->together=true;
        $criteria->compare('requestKonsumen.id', $this->requestKonsumenId,true);
        $criteria->compare('requestKonsumen.status',$this->requestKonsumenStatus,true);
        $criteria->compare('type.id',$this->typeMakanan);
        
        
     //   $sort = new CSort;
           //     $sort->defaultOrder = 'requestKonsumen.id ASC';
             //   $sort->attributes = array(
                			
               //     'Request Konsumen ID' => array(
                 //           'asc'=>'requestKonsumen.id',
                   //         'desc'=>'requestKonsumen.id DESC',
                     //   ),
               // );
                       
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria, //'sort' =>$sort
		));
	}
}
